﻿using Quartz;
using QuartzServices.Infrastructure.Common.Constant;
using QuartzServices.Web.Quartz;

namespace QuartzServices.Web.Extensions
{
    public static class QuartzNetSetup
    {
        public static void AddQuartzNetSetup(this IServiceCollection services) 
        {
            services.AddQuartz(d =>
            {
                d.UseSimpleTypeLoader();
                d.UseInMemoryStore();
                d.UseDefaultThreadPool(p => p.MaxConcurrency = 10);
                d.UseMicrosoftDependencyInjectionJobFactory();

                var blcSapLocationJobkey = new JobKey(JobNameConstant.BlcSapLocation);
                d.AddJob<TestJob>(blcSapLocationJobkey);
                d.AddTrigger(p => p
                    .ForJob(blcSapLocationJobkey)
                    .StartNow()
                    .WithCronSchedule("0/10 * * * * ?"));
            });

            services.AddTransient<TestJob>();

            services.AddQuartzHostedService(d => { d.WaitForJobsToComplete = true; });

        }
    }
}
